<template>
	<view class="homeLayout pageBg">
		<!-- 导航栏 -->
		<custom-nav-bar title="推荐"></custom-nav-bar>
		<!-- 轮播 -->
		<view class="banner">
			<swiper indicator-dots indicator-color="#aaaaaa" indicator-active-color="#fff" autoplay circular>
				<swiper-item v-for="item in bannerList" :key="item._id">
					<image mode="aspectFill" :src="item.picurl"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 公告 -->
		<view class="notice">
			<view class="notice-left">
				<uni-icons type="sound-filled" size="20"></uni-icons>
				<text class="notice-left-text">公告</text>
			</view>
			<view class="notice-center">
				<swiper vertical autoplay circular interval="1500" duration="300">
					<swiper-item v-for="item in noticeList" :key="item._id">{{item.title}}</swiper-item>
				</swiper>
			</view>
			<view class="notice-right">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>
		</view>
		<!-- 每日推荐 -->
		<view class="img-select">
			<common-title title="每日推荐">
				<template #custom>
					<view class="date">					
						<uni-icons type="calendar" size="18"></uni-icons>
						<uni-dateformat class="date-text" :date="Date.now()" format="dd日"></uni-dateformat>
					</view>
				</template>
			</common-title>
			<view class="content">
				<scroll-view class="select-scroll" scroll-x>
					<view class="select-item" v-for="item in dayRandomList" :key="item._id" @click="toPreviewPage(item._id)">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 专题精选 -->
		<view class="theme">
			<common-title title="专题精选">
				<template #custom>					
					<navigator url="/pages/classify/classify" open-type="switchTab" class="more">
						More+
					</navigator>
				</template>
			</common-title>
			<view class="content">
				<view class="item" v-for="item in classifyList" :key="item._id">
					<theme-item :item="item"></theme-item>
				</view>
				<theme-item :isMore="true"></theme-item>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {onShareAppMessage, onShareTimeline} from '@dcloudio/uni-app';
	import {ref} from "vue";
	import {apiGetBanner,apiGetNotice,apiGetDayRandom,apiGetClassify} from "../../api/apis.js";
	// 获取轮播图接口
	const bannerList = ref([])
	const getBannerList = async () => {
		let res = await apiGetBanner();
		bannerList.value = res.data
	}
	getBannerList()
	// 获取公告接口
	const noticeList = ref([])
	const getNoticeList = async () => {
		let res = await apiGetNotice();
		noticeList.value = res.data
	}
	getNoticeList()
	// 获取每日推荐接口
	const dayRandomList = ref([])
	const getDayRandomList = async () => {
		let res = await apiGetDayRandom();
		dayRandomList.value = res.data
	}
	getDayRandomList()
	// 获取专题精选接口
	const classifyList = ref([])
	const getClassifyList = async () => {
		let res = await apiGetClassify({select: true});
		classifyList.value = res.data	
	}
	getClassifyList()
	
	
	// 每日推荐跳转到预览页面
	const toPreviewPage = (id) => {
		uni.navigateTo({
			url: "/pages/preview/preview?id="+id + "&fromHome=true"
		})
	}
	
	// 用户点击分享小程序
	onShareAppMessage((e) => {
		return {
			title: "雪人壁纸",
			path: "/pages/index/index"
		}
	})
	// 分享朋友圈
	onShareTimeline((e) => {
		return {
			title: "雪人壁纸"
		}
	}) 
</script>

<style lang="scss" scoped>
	.homeLayout {
		padding: 30rpx;
		.banner {
			width: 690rpx;
						border-radius: 90rpx;
			swiper {
				width: 690rpx;
				height: 340rpx;
				&-item {
					width: 100%;
					height: 100%;
					image {
						width: 100%;
						height: 100%;
					}
				}
			}
		}
		.notice {
			width: 690rpx;
			height: 80rpx;
			line-height: 80rpx;
			background-color: #f9f9f9;
			border-radius: 80rpx;
			margin: 30rpx auto;
			display: flex;
			&-left {
				width: 170rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				:deep(){
					.uni-icons {
						color: $brand-theme-color !important;
					}
				}
				&-text {
					color: $brand-theme-color;
					font-weight: 600;
					font-size: 28rpx;
				}
			}
			&-center {
				flex: 1;
				swiper {
					height: 100%;
					&-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}
			&-right {
				width: 70rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
		.img-select {
			.date {
				display: flex;
				align-items: center;
				justify-content: center;
				:deep(){
					.uni-icons {
						color: $brand-theme-color !important;
					}
				}
				.date-text {
					margin-left: 5rpx;
					color: $brand-theme-color;
				}
			}
			.content {
				width: 690rpx;
				.select-scroll {
					white-space: nowrap;
					.select-item {
						display: inline-block;
						margin-right: 15rpx;
						image {
							width: 200rpx;
							height: 430rpx;
							border-radius: 10rpx;
						}
					}
					.select-item:last-child {
						margin-right: 30rpx;
					}
				}
			}
		}
		.theme {
			.more {
				font-size: 32rpx;
				color: #888;
			}
			.content {
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3,1fr);
				.item {
				}
			}
		}
	}
</style>
